package com.example.book_libapp;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BookListAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public BookListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.book_itemrow, null);

		TextView title = (TextView) vi.findViewById(R.id.title); // title
		TextView info = (TextView) vi.findViewById(R.id.breif); // info name
		TextView book_id = (TextView) vi.findViewById(R.id.book_id); // book id
		ImageView thumb_image = (ImageView) vi.findViewById(R.id.list_image); // cover
																				// image
		// book_id.setVisibility(View.GONE);

		HashMap<String, String> book = new HashMap<String, String>();
		book = data.get(position);

		// Setting all values in listview
		title.setText(book.get(ListViewBookActivity.TAG_TITLE));
		info.setText(book.get(ListViewBookActivity.TAG_INFO));
		book_id.setText(book.get(ListViewBookActivity.TAG_ID));
		imageLoader.DisplayImage(book.get(ListViewBookActivity.TAG_COVER),
				thumb_image);
		return vi;

	}
}